﻿<?php
$connect=mysql_connect("localhost","root","");
mysql_select_db("shenji",$connect);
$sql2="select count(*) as amount from shenji";
$result=mysql_query($sql2);
$row=mysql_fetch_array($result);
$count=$row['amount'];
$pagesize=10;

if($count%$pagesize){
	$page=ceil($count/$pagesize);
}else{
	$page=$count/$pagesize;
}
if(isset($_GET['currentpage'])){
	$currentpage=intval($_GET['currentpage']);
}else{
	$currentpage=1;
}
$start=($currentpage-1)*$pagesize;
$sql="select * from shenji order by field(type,'云图','升级'),move desc limit $start,$pagesize";
$result = mysql_query($sql);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<style>
      .tip{
		  width:600px;
		  height:280px;
	  }

</style>
<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
     $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
     $(".tip").fadeOut(200);
  });



});
</script>
</head>
<body>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">升级包管理</a></li>
    <li><a href="#">升级包列表</a></li>
    </ul>
    </div>
	
    <div class="rightinfo">
    
    <div class="tools">
    	<ul class="toolbar">
        <li class="click" onclick="ck(0)"><span><img src="images/t01.png" /></span>添加</li>
        </ul>
    </div>
	
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input  type="checkbox" name="checkbox" onclick="selectAll(this)"/></th>
        <th>升级包类型</th>
        <th>版本</th>
        <th>上传人</th>
		<th>上传时间</th>
	    <th>升级包下载开启状态</th>
		<th>测试机器</th>
		<th>操作</th>
        </tr>
        </thead>
        <tbody>
		 <?php   
	     while($row=mysql_fetch_array($result)){
	    ?>
		<tr>
        <td><input  type="checkbox" name="son_checkbox" value="<?php echo $row['id'];?>"/></td>
        <td><?php echo $row['type'];?></td>
        <td><?php echo 	sprintf("%1\$.2f",$row['version']*0.01);?></td>
        <td><?php echo $row['username'];?></td>
		<td><?php echo $row['uploadtime'];?></td>
		<?php 
			if($row['publish_jiqi']==1){
				$kggb="<a href='#' onclick='kq(".$row["id"].")'>关闭</a>";
			} else{
				$kggb="开启";
			}
	    ?>
		<td><?php echo $kggb;?></td>
		<?php
		
		$jiekou_id=$row['jiekou_id'];
		$select_jid="select * from jiekou where id=$jiekou_id";
		$s_result=mysql_query($select_jid);
		$s_row=mysql_fetch_array($s_result);
		$beizhu=$s_row['beizhu'];
	   ?>
	   <td><?php echo $beizhu;?></td>
	   <td><a  onclick="ck('<?php echo $row['id'];?>');" class="tablelink" href="#">修改&nbsp;&nbsp;&nbsp;&nbsp;</a> <a onclick="shanchu('<?php echo $row['id'];?>');" onmouseover="this.style.cursor='pointer'" class="tablelink"> 删除&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="tablelink" href="move.php?action=up&&type=<?php echo $row['type']; ?>&&move=<?php echo $row['move'];?>" title="版本上移">上移&nbsp;&nbsp;&nbsp;&nbsp;</a><a class="tablelink" href="move.php?action=down&&type=<?php echo $row['type'];?>&&move=<?php echo $row['move'];?>" title="版本下移">下移</a></td>
        </tr> 
		<?php
		 }
		?>
        </tbody>
    </table>
	
    <div class="pagin">
    	<div class="message">共<i class="blue"><?php echo $page;?></i>页，当前显示第&nbsp;<i class="blue"><?php echo $currentpage; ?>&nbsp;</i>页</div>
        <ul class="paginList">
        <li class="paginItem"><a href="select_shenji.php?currentpage=<?php if(intval($currentpage)>1){echo intval($currentpage-1);}else{echo 1;}?>"><span class="pagepre"></span></a></li>
        <li class="paginItem current"><a href="select_shenji.php?currentpage=<?php echo $currentpage;?>"><?php echo intval($currentpage)?></a></li>
        <?php
		    if(intval($currentpage+1)<=$page){
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+1);?>"><?php echo intval($currentpage+1);?></a></li>
		<?php
			}if(intval($currentpage+2)<=$page){
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+2);?>"><?php echo intval($currentpage+2);?></a></li>
		<?php		
			}if(intval($currentpage+3)<=$page){
				
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+3);?>"><?php echo intval($currentpage+3);?></a></li>
		<?php
			}if(intval($currentpage+4)<=$page){
				
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+4);?>"><?php echo intval($currentpage+4);?></a></li>
		<?php
			}if(intval($currentpage+5)<=$page){
				
	    ?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+5);?>"><?php echo intval($currentpage+5);?></a></li>
		<?php
			}if(intval($currentpage+6)<=$page){
				
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+6);?>"><?php echo intval($currentpage+6);?></a></li>
		<?php
			}if(intval($currentpage+7)<=$page){
				
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+7);?>"><?php echo intval($currentpage+7);?></a></li>
		<?php
			}if(intval($currentpage+8)<=$page){
				
	    ?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+8);?>"><?php echo intval($currentpage+8);?></a></li>
		<?php
			}if(intval($currentpage+9)<=$page){
		?>
		    <li class="paginItem"><a href="select_shenji.php?currentpage=<?php echo intval($currentpage+9);?>"><?php echo intval($currentpage+9);?></a></li>
		<?php
			}
		?>


        <li class="paginItem"><a href="select_shenji.php?currentpage=<?php if(intval($currentpage)<intval($page)){echo intval($currentpage+1);}else{echo $page;}?>"><span class="pagenxt"></span></a></li>
		<li class="paginItem"></li>
        </ul>
    </div>
	
    <div class="tip">
	  <div class="tiptop"><span>添加升级包</span><a></a></div>
      <div class="formbody">
        <form method="post" action="insert_shenji_commit.php" enctype="multipart/form-data">
		    <input size="20" type="hidden" name="id" id="id">
			<ul class="forminfo">
			<li>
			<label>类型</label>
			<select name="type" id="type" style="width:80px;">
			<?php
			  //从数据库中取出类型type
			  $sql2="select * from type";
			  $result2=mysql_query($sql2);
			  while($row2=mysql_fetch_array($result2)){  
			?>
			 <option value="<?php echo $row2['name'];?>"><?php echo $row2['name'];?></option>
			<?php
			 }
			?>
			</select>
			</li>
			<li><label>升级包</label><input name="file" id="file" type="file" style="width:122px;"/></li>
			<li><label>测试的机器码</label>
			<select id="publish_jiqi" name="publish_jiqi">
			<?php
				$jiekou_sql="select * from jiekou";
				$jiekou_result=mysql_query($jiekou_sql);	 
				while($jk_row=mysql_fetch_array($jiekou_result)){	   		   
			?>
				<option value="<?php echo $jk_row['id'];?>"><?php echo $jk_row['beizhu'];?></option>	 
			<?php
				}
			?>
			</select>
			</li>
			<li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认保存" onclick="return tijiao();"/></li>
			</ul>
		</form>
      </div>
      <!--
	  <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" />&nbsp;
      <input name="" type="button"  class="cancel" value="取消" />
      </div>
	  -->
	  
    </div>
    </div>
    
<script type="text/javascript">
    function ck(id){
		if(id==0){//添加  
		   $("#id").val("");
		   $("#type").val("");
		   $("#publish_jiqi").val("");
			
		}else{  //编辑
			 $.post("select_shenji_id.php",{id:id},function(data){
				   $("#type").val(data['type']);
				   var jiekou_id=data['jiekou_id'];
				   $("#id").val(data['id']);
			       //var beizhu=getbeizhu(jiekou_id);
				   //var  b=beizhu
				   $("#publish_jiqi").val(jiekou_id);
				   //$("#publish_jiqi option[value='3']").attr("selected", true); 
				   // $("#select option[text='"+jiekou_id+"']").attr("selected", "selected"); 
				   $(".tip").fadeIn(200);
			},"json")
		}
	}
	var getbeizhu=function(jiekou_id){
			 var a="";
			 $.ajax({
				 type:"post",
				 url:"get_jiekou.php",
				 data:"jiekou_id="+jiekou_id,
				 async:false,
				 success:function(data){
					 a=data;
				 }
			 })
			 return a;
		   /*  $.post("get_jiekou.php",{jiekou_id:jiekou_id},function(data){
				 a=data;
				 
			 },async:false)*/
	}
	
	function shanchu(id){
		if(confirm("您确定要删除所选择的升级包吗")){
			    
				$.post("delete_shenji.php",{id:id},function(data){
				  if(data!=null){
					  alert(data);
				  }
				   window.location.reload();
				},"json")
				
		}else{
				return false;
		}
	}
   
    function ok(){
		var currentpage=$("#textpage").val();
		var currentpage2=parseInt(currentpage);
		
		var page="<?php echo $page;?>";
		var page2=parseInt(page);
		
		
		if(currentpage2>0&&currentpage2<=page2){
			window.location.href="../select/select_shenji.php?currentpage="+currentpage2;
		}else{
			var d_currentpage="<?php echo $currentpage?>";
			var d_currentpage2=parseInt(d_currentpage);
		    window.location.href="../select/select_shenji.php?currentpage="+d_currentpage2;
		}
	}
	
	function selectAll(objs)
    {
    obj=document.getElementsByName('checkbox1');
    for(var i=0;i<obj.length;i++){
	if(objs.checked){
		obj.item(i).checked=true;
	}else{
		obj.item(i).checked=false; 
	}  
  }
}

function shanchu(id){
	if(confirm("您确定要删除所选择的升级包吗")){
			$.post("delete_shenji.php",{id:id},function(data){
			  if(data!=null){
				  alert(data);
			  }
			   window.location.reload();
			},"json")
			
	}else{
			return false;
	}
}
function kq(id){
	$.post("change.php",{id:id},function(data){
			   window.location.reload();
	})
}

function tijiao(){
	var name=$("#file").val();  
	var re =/update+\w*.tar.gz/;
	var result=re.test(name);
	var fileInput = $("#file")[0];
	var byteSize  = fileInput.files[0].size;
	var size1=Math.ceil(byteSize/1024000);
    if(result&&size1<=200){
		return true;			
	}else{
		 alert("请输入正确的升级文件update*.tar.gz并且文件大小不超过200M"); 
		 return false;
	} 
}
	
</script>
</body>
</html>
